<template>
    <div>
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
            <el-row :gutter="20">
                <el-col :span="16">
                    <el-row :gutter="10">
                        <el-col :span="20">
                            <el-form-item label="课程名称" prop="name">
                                <el-input v-model="dataForm.name" placeholder="课程名称"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="4">
                            <el-button size="mini" type="primary" :disabled="!autoEdite" @click="autoCreateName">自动生成</el-button>
                        </el-col>
                    </el-row>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="课程状态" prop="status">
                        <el-select v-model="dataForm.status"  placeholder="请选择">
                            <el-option
                            v-for="item in statusOptions"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="20">
                
                <el-col :span="8">
                    <el-form-item label="年份" prop="year">
                        <el-select v-model="dataForm.year"  placeholder="请选择">
                            <el-option
                            v-for="item in yearOptions"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="季节" prop="season">
                        <el-select v-model="dataForm.season"  placeholder="请选择">
                            <el-option
                            v-for="item in seasonOptions"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="年级" prop="gradeId">
                        <el-select v-model="dataForm.gradeId"  placeholder="请选择">
                            <el-option
                            v-for="item in gradeOptions"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="20">
                <el-col :span="8">
                    <el-form-item label="课程科目" prop="subjectId">
                        <el-select v-model="dataForm.subjectId"  placeholder="请选择">
                            <el-option
                            v-for="item in subjectOptions"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="班级类型" prop="classTypeId">
                        <el-select v-model="dataForm.classTypeId"  placeholder="请选择">
                            <el-option
                            v-for="item in classTypeOptions"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="课程分类" prop="categoryId">
                        <el-select v-model="dataForm.categoryId"  placeholder="请选择">
                            <el-option
                            v-for="item in categoryOptions"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="20">
                <el-col :span="8">
                    <el-form-item label="校区" prop="schoolId">
                        <el-select v-model="dataForm.schoolId"  placeholder="请选择">
                            <el-option
                            v-for="item in schoolOptions"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="教师" prop="teacherId">
                        <el-select v-model="dataForm.teacherId"  placeholder="请选择">
                            <el-option
                            v-for="item in teacherOptions"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="销售价格" prop="price">
                    <el-input v-model="dataForm.price" placeholder="销售价格(元)"></el-input>
                    </el-form-item>
                </el-col>
                
            </el-row>
            <el-row :gutter="20">
                <el-col :span="8">
                    <el-form-item label="总课时" prop="lessonNum">
                    <el-input v-model="dataForm.lessonNum" placeholder="总课时"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="班级人数" prop="totalNum">
                    <el-input v-model="dataForm.totalNum" placeholder="请输入班级总人数"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="课程频次" prop="rate">
                        <el-input v-model="dataForm.rate" maxlength="8" placeholder="请输入课程频次"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="20">
                <el-col :span="8">
                    <el-form-item label="开始时间" prop="startTime">
                        <el-date-picker
                            v-model="dataForm.startTime"
                            type="date"
                            format="yyyy 年 MM 月 dd 日"
                            value-format="yyyy-MM-dd"
                            placeholder="选择开始日期">
                        </el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="结束时间" prop="endTime">
                        <el-date-picker
                            v-model="dataForm.endTime"
                            type="date"
                            format="yyyy 年 MM 月 dd 日"
                            value-format="yyyy-MM-dd"
                            placeholder="选择解释日期">
                        </el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label="校验分数" prop="isValid">
                        <el-select v-model="dataForm.isValid"  placeholder="请选择">
                            <el-option
                            v-for="item in isValidOptions"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="20">
                <el-col :span="8">
                    <el-form-item label="正式班" prop="isFormal">
                        <el-select v-model="dataForm.isFormal"  placeholder="请选择">
                            <el-option
                            v-for="item in isFormalOptions"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="要求分数" prop="score">
                    <el-input v-model="dataForm.score" placeholder="请输入分数不能有汉字"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label="课程列表" prop="isOver">
                        <el-button type="primary" @click="addLesson()">{{ !dataList.length? '添加' : '编辑'}}</el-button>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="20">
                <el-col :span="8">
                    <el-form-item label="班级图片" >
                        <el-upload
                            class="avatar-uploader"
                            :action= uploadUrl
                            :show-file-list="false"
                            :on-success="handleAvatarSuccess">
                            <img v-if="dataForm.uploadUrl" :src="dataForm.uploadUrl" class="avatar">
                            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                        </el-upload>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="班级简介">
                    <el-input type="textarea" :autosize="{ minRows: 4}" v-model="dataForm.introduction" placeholder="请输入班级简介"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <div  class="footer">
                <el-button @click="$router.go(-1)">取消</el-button>
                <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
            </div>

        </el-form>
        <!-- 课程列表弹窗 -->
        <el-dialog
        title="添加课程时间列表"
        :close-on-click-modal="false"
        :visible.sync="lessonVisible">
            <div class="add-form">
                <el-form :model="addForm" ref="addDataForm">
                    <el-row :gutter="10">
                        <el-col :span="12">
                            <el-date-picker
                                v-model="addForm.lessonPeriod"
                                type="date"
                                format="yyyy 年 MM 月 dd 日"
                                value-format="yyyy-MM-dd"
                                placeholder="选择上课日期">
                            </el-date-picker>
                        </el-col>
                        <el-col :span="12">
                            <el-time-picker
                                v-model="addForm.startTime"
                                :picker-options="{
                                selectableRange: '7:00:00 - 21:00:00'
                                }"
                                :clearable="false"
                                value-format="HH:mm:ss"
                                placeholder="上课时间">
                            </el-time-picker>
                        </el-col>
                    </el-row>
                    <div class="search-style">
                        <el-row :gutter="10">
                        
                            <el-col :span="12">
                                <el-time-picker
                                    v-model="addForm.endTime"
                                    :picker-options="{
                                    selectableRange: '7:00:00 - 21:00:00'
                                    }"
                                    value-format="HH:mm:ss"
                                     :clearable="false"
                                    placeholder="下课时间">
                                </el-time-picker>
                            </el-col>
                            <el-col :span="12">
                                <el-button type="primary" @click="addlessonPeriod()">新增</el-button>
                            </el-col>
                        </el-row>
                    </div>
                </el-form>
            </div>
            
            <div style="height: 300px;overflow:auto;">
                <el-table
                :data="dataList"
                border
                v-loading="dataListLoading"
                @selection-change="selectionChangeHandle"
                style="width: 100%;">
                <el-table-column
                    type="selection"
                    header-align="center"
                    align="center"
                    width="50">
                </el-table-column>
                <el-table-column
                    type="index"
                    header-align="center"
                    align="center"
                    label="序号"
                    width="50">
                </el-table-column>
                <el-table-column
                    prop="lessonPeriod"
                    header-align="center"
                    align="center"
                    label="上课年月日">
                </el-table-column>
                <el-table-column
                    prop="startTime"
                    header-align="center"
                    align="center"
                    
                    label="当天起始时间">
                </el-table-column>
                <el-table-column
                    prop="endTime"
                    header-align="center"
                    align="center"
                    label="当天结束时间">
                </el-table-column>
                <el-table-column
                    fixed="right"
                    header-align="center"
                    align="center"
                    width="80"
                    label="操作">
                    <template slot-scope="scope">
                        <el-button type="text" size="small" @click="deleteHandle(scope.$index)">删除</el-button>
                    </template>
                </el-table-column>
                </el-table>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="cancelSelect()">取消</el-button>
                <el-button type="primary" @click="sureSelect()">确定</el-button>
            </span>
        </el-dialog>

    </div>
</template>

<script>
import { getNowFormatDate } from '@/utils'
  export default {
    data () {
      return {
        autoEdite: false,
        lessonVisible: false,
        dataList: [],
        dataListLoading: false,
        addForm: {
          startTime: '',
          endTime: '',
          lessonPeriod: '',
        },
        uploadUrl: this.$http.adornUrl(`/sys/oss/upload?token=${this.$cookie.get('token')}`),
        dataForm: {
          type: '',
          id: 0,
          name: '',
          status: 1,//新建默认状态是发布
          price: '',
          startTime: '',
          endTime: '',
          schoolId: '',
          teacherId: '',
          subjectId: '',
          classTypeId: '',
          categoryId: '',
          gradeId: '',
          lessonNum: '',
          restCount: '',
          score: '',
          isOver: '',
          isValid: 1,//是否需要校验班级
          isFormal: 1,//是否是正式班
          rate: '',
          isDeleted: '',
          version: '',
          gmtCreate: '',
          gmtModified: '',
          totalNum: '',
          year:'',//所属年份
          season: '',//季节
          introduction: '',//班级简介
          uploadUrl: '',//班级图片
        },
        isFormalOptions: [
            {
            value: 1,
            label: '是'
          },
            {
            value: 0,
            label: '否'
          }, 
        ],
        isValidOptions: [
            {
            value: 1,
            label: '是'
          },
            {
            value: 0,
            label: '否'
          },
        ],
        statusOptions: [
            {
            value: 0,
            label: '草稿'
          }, {
            value: 1,
            label: '发布'
          },
          {
            value: 2,
            label: '作废'
          },
          {
            value: 5,
            label: '其他'
          }
        ],
        isOverOptions: [
             {
            value: 0,
            label: '否'
          },
          {
            value: 1,
            label: '是'
          }
        ],
        schoolOptions: [],
        teacherOptions: [],
        subjectOptions: [],
        classTypeOptions: [],
        categoryOptions: [],
        gradeOptions: [],
        yearOptions:[
            {
                value: new Date().getFullYear(),
                label: `${new Date().getFullYear()}年`
            },
            {
                value: (new Date().getFullYear() + 1),
                label: `${new Date().getFullYear()+ 1}年`
            },
        ],
        seasonOptions: [
            {
                value: 0,
                label: '春'
            },
            {
                value: 1,
                label: '暑'
            },
            {
                value: 2,
                label: '秋'
            },
            {
                value: 3,
                label: '寒'
            },
        ],
        dataRule: {
          name: [
            { required: true, message: '课程名称不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '课程状态不能为空', trigger: 'blur' }
          ],
          price: [
            { required: true, message: '销售价格不能为空', trigger: 'blur' }
          ],
          startTime: [
            { required: true, message: '开始时间不能为空', trigger: 'blur' }
          ],
          endTime: [
            { required: true, message: '结束时间不能为空', trigger: 'blur' }
          ],
          rate:[
            { required: true, message: '课程频次不能为空', trigger: 'blur' }
          ],
          schoolId: [
            { required: true, message: '校区不能为空', trigger: ["blur",'change'] }
          ],
          teacherId: [
            { required: true, message: '教师不能为空', trigger: ["blur",'change'] }
          ],
          subjectId: [
            { required: true, message: '课程科目不能为空', trigger: ["blur",'change'] }
          ],
          classTypeId: [
            { required: true, message: '班级类型不能为空', trigger: ["blur",'change'] }
          ],
          categoryId: [
            { required: true, message: '课程分类不能为空', trigger: ["blur",'change'] }
          ],
          gradeId: [
            { required: true, message: '年级不能为空', trigger: ["blur",'change'] }
          ],
          lessonNum: [
            { required: true, message: '总课时不能为空', trigger: 'blur' },
            { type: 'integer', message: '总课时必须是数字', trigger: 'blur',transform: value => this.$options.filters.formValidateFun(value, "number") }
          ],
          totalNum: [
            { required: true, message: '班级人数不能为空', trigger: 'blur' },
            { type: 'integer', message: '班级人数必须是数字', trigger: 'blur',transform: value => this.$options.filters.formValidateFun(value, "number") }
          ],
          score: [
            { required: true, message: '要求分数不能为空', trigger: 'blur' }
          ],
          year: [
            { required: true, message: '所属年份不能为空', trigger: ['blur','change'] }
          ],
          season: [
            { required: true, message: '季节不能为空', trigger:'change' }
          ],
         
        }
      }
    },
    computed: {
        documentClientHeight: {
        get () { return this.$store.state.common.documentClientHeight }
      },
      menuActiveName: {
        get () { return this.$store.state.common.menuActiveName },
        set (val) { this.$store.commit('common/updateMenuActiveName', val) }
      },
      mainTabs: {
        get () { return this.$store.state.common.mainTabs },
        set (val) { this.$store.commit('common/updateMainTabs', val) }
      },
      mainTabsActiveName: {
        get () { return this.$store.state.common.mainTabsActiveName },
        set (val) { this.$store.commit('common/updateMainTabsActiveName', val) }
      },
    },
    methods: {
        handleAvatarSuccess(res, file) {
            this.dataForm.uploadUrl = res.url;
        },
         // tabs, 删除tab
      removeTabHandle (tabName) {
        this.mainTabs = this.mainTabs.filter(item => item.name !== tabName)
        if (this.mainTabs.length >= 1) {
          // 当前选中tab被删除
          if (tabName === this.mainTabsActiveName) {
            var tab = this.mainTabs[this.mainTabs.length - 1]
            this.$router.push({ name: tab.name, query: tab.query, params: tab.params }, () => {
              this.mainTabsActiveName = this.$route.name
            })
          }
        } else {
          this.menuActiveName = ''
          this.$router.push({ name: 'home' })
        }
      },
      // tabs, 关闭当前
      tabsCloseCurrentHandle () {
        this.removeTabHandle(this.mainTabsActiveName)
      },
        autoCreateName() {
            let seasonName = '';
            let subjectName = '';
            let classTypeName = '';
            let gradeName = '';
            const that = this;
            this.seasonOptions.forEach((item)=>{
                if(item.value == that.dataForm.season) {
                    seasonName = item.label
                }
            })
            this.subjectOptions.forEach((item)=>{
                if(item.value == that.dataForm.subjectId) {
                    subjectName = item.label
                }
            })

            this.gradeOptions.forEach((item)=>{
                if(item.value == that.dataForm.gradeId) {
                    gradeName = item.label
                }
            })
             this.classTypeOptions.forEach((item)=>{
                if(item.value == that.dataForm.classTypeId) {
                    classTypeName = item.label
                }
            })
            
            this.dataForm.name = `${this.dataForm.year}${seasonName}季${gradeName}${subjectName}${classTypeName}`;
        },
         addLesson() {
             if(this.dataForm.startTime && this.dataForm.endTime) {
                 this.lessonVisible = true;
             }else{
                 this.$message({
                     message: '请先选择开始时间和结束时间',
                     type: 'warning'
                 })
             }
             
         },
         cancelSelect(){
            this.addForm = {
                startTime: '',
                endTime: '',
                lessonPeriod: '',
            }
            this.lessonVisible = false;
                
         },
         sureSelect() {
             this.lessonVisible = false;
         },
        addlessonPeriod() {
            if(!this.addForm.lessonPeriod) {
                return this.$message.error('请选择上课日期')
            }
            if(!this.addForm.startTime) {
                return this.$message.error('请选择上课时间')
            }
            if(!this.addForm.endTime) {
                return this.$message.error('请选择下课时间')
            }

            let lessonPeriodTimeStamp = new Date(this.addForm.lessonPeriod).getTime();
            let startTimeStamp = new Date(this.dataForm.startTime).getTime();
            let endTimeStamp = new Date(this.dataForm.endTime).getTime();
            console.log(this.dataForm.endTime);
            if( lessonPeriodTimeStamp >= startTimeStamp && lessonPeriodTimeStamp <= endTimeStamp) {
                let lessonInfo = {}
                lessonInfo.startTime = this.addForm.startTime;
                lessonInfo.endTime = this.addForm.endTime;
                lessonInfo.lessonPeriod = this.addForm.lessonPeriod;
                this.dataList.push(lessonInfo)
            }else{
                this.$message.error('日期必须在班级开始时间和结束时间段内');
            }
                    

        },
        deleteHandle(index) {
            this.dataList.forEach( (item,_index) => {
                if(index == _index) {
                    this.dataList.splice(_index ,1);
                }
            })
        },
        selectionChangeHandle() {

        },
      //获取公共列表
      getCommonList() {
          this.$http({
            url: this.$http.adornUrl('/sys/common/list'),
            method: 'get',
            params: this.$http.adornParams()
          }).then(({data}) => {
            if(data && data.code === 0) {
                let schoolOptions = data.school || [];
                let subjectOptions = data.subject || [];
                let classTypeOptions = data.classType || [];
                let categoryOptions = data.category || [];
                let gradeOptions = data.grade || [];
                let teacherOptions = data.teacher || [];
                schoolOptions.forEach((item) => {
                    item.value = item.id;
                    item.label = item.name;
                })
                subjectOptions.forEach((item) => {
                    item.value = item.id;
                    item.label = item.name;
                })
                classTypeOptions.forEach((item) => {
                    item.value = item.id;
                    item.label = item.name;
                })
                categoryOptions.forEach((item) => {
                    item.value = item.id;
                    item.label = item.name;
                })
                gradeOptions.forEach((item) => {
                    item.value = item.id;
                    item.label = item.name;
                })
                teacherOptions.forEach((item) => {
                    item.value = item.id;
                    item.label = item.name;
                })

                this.schoolOptions = schoolOptions;
                this.subjectOptions = subjectOptions;
                this.classTypeOptions = classTypeOptions;
                this.categoryOptions = categoryOptions;
                this.gradeOptions = gradeOptions;
                this.teacherOptions = teacherOptions;

            }
          })
      },
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/sys/educlass/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.name = data.eduClass.name
                this.dataForm.status = data.eduClass.status
                this.dataForm.price = data.eduClass.price
                this.dataForm.startTime = data.eduClass.startTime
                this.dataForm.endTime = data.eduClass.endTime
                this.dataForm.schoolId = data.eduClass.schoolId
                this.dataForm.teacherId = data.eduClass.teacherId
                this.dataForm.subjectId = data.eduClass.subjectId
                this.dataForm.classTypeId = data.eduClass.classTypeId
                this.dataForm.categoryId = data.eduClass.categoryId
                this.dataForm.gradeId = data.eduClass.gradeId
                this.dataForm.lessonNum = data.eduClass.lessonNum
                this.dataForm.restCount = data.eduClass.restCount
                this.dataForm.score = data.eduClass.score
                this.dataForm.isOver = data.eduClass.isOver
                this.dataForm.isDeleted = data.eduClass.isDeleted
                this.dataForm.version = data.eduClass.version
                this.dataForm.gmtCreate = data.eduClass.gmtCreate
                this.dataForm.gmtModified = data.eduClass.gmtModified
                this.gmtCreate = data.eduClass.gmtCreate;
                this.dataForm.totalNum = data.eduClass.totalNum
                this.dataForm.year = data.eduClass.year
                this.dataForm.isValid = data.eduClass.isValid
                this.dataForm.isFormal = data.eduClass.isFormal
                this.dataForm.rate = data.eduClass.rate || ''
                this.dataForm.season = data.eduClass.season
                this.dataList = data.eduClass.lessonEntityList
                this.dataForm.introduction = data.eduClass.introduction
                this.dataForm.uploadUrl = data.eduClass.uploadUrl
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
          
        this.$refs['dataForm'].validate((valid) => {
            console.log(valid)
            if (valid) {
                if(this.dataList.length <= 0) {
                    this.$message.error('课程列表不能为空')
                    return ;
                }
                let urls = '';
                if(this.dataForm.id && this.type  == 'add') {
                    urls = '/sys/educlass/save'
                }
                if(!this.dataForm.id) {
                     urls = '/sys/educlass/save'
                }
                if(this.dataForm.id && this.type != 'add') {
                    urls = '/sys/educlass/update'
                }
                this.$http({
                url: this.$http.adornUrl(urls),
                method: 'post',
                data: this.$http.adornData({
                'id': (this.dataForm.id && this.type != 'add')? this.dataForm.id : undefined,
                'name': this.dataForm.name,
                'status': this.dataForm.status,
                'price': Number(this.dataForm.price),
                'startTime': this.dataForm.startTime,
                'endTime': this.dataForm.endTime,
                'schoolId': this.dataForm.schoolId,
                'teacherId': this.dataForm.teacherId,
                'subjectId': this.dataForm.subjectId,
                'classTypeId': this.dataForm.classTypeId,
                'categoryId': this.dataForm.categoryId,
                'gradeId': this.dataForm.gradeId,
                'lessonNum': Number(this.dataForm.lessonNum),
                'restCount': Number(this.dataForm.restCount),
                'score': Number(this.dataForm.score),
                'isOver': this.dataForm.isOver,
                'isDeleted': this.dataForm.isDeleted,
                'isValid': this.dataForm.isValid,
                'isFormal': this.dataForm.isFormal,
                'rate' : this.dataForm.rate,
                'totalNum': Number(this.dataForm.totalNum),
                'year': this.dataForm.year,
                'season': this.dataForm.season,
                'lessonEntityList': this.dataList,
                'uploadUrl': this.dataForm.uploadUrl,
                'introduction': this.dataForm.introduction
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    // this.$refs['dataForm'].resetFields();
                    // this.$refs['addDataForm'].resetFields();
                    this.tabsCloseCurrentHandle();
                    // this.$router.go(-1);

                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    },
    watch: {
        dataForm:{
            handler(newName, oldName) {
                console.log(newName);
                if( this.dataForm.year && (this.dataForm.season >=0)
                    && this.dataForm.gradeId && this.dataForm.subjectId
                    && this.dataForm.classTypeId
                ){
                    console.log('true')
                    this.autoEdite = true;
                }
                if(this.dataForm.isValid == 0) {
                    this.dataRule.score = [{ required: false, message: '要求分数不能为空', trigger: 'blur' }];
                }else{
                    this.dataRule.score = [{ required: true, message: '要求分数不能为空', trigger: 'blur' }]
                }
            },
            deep: true,
            immediate: true
        }
    },
    created: function() {
        this.getCommonList();
        let id = this.$route.query.id;
        this.type = this.$route.query.type || '';
        if(id) {
            this.init(id);
        }


    }
  }
</script>
<style scoped>
.el-button{
    margin-top: 4px!important;
    padding: 7px!important;
}
.footer{
    margin-left: 200px;
}
.footer .el-button{
    width: 200px;
    height: 40px;
}
.add-form{
    padding: 10px;
    border: 1px dashed #ccc;
    margin-bottom: 10px;
}
.add-form  .el-button {
    width: 100px;

}
.dialog-footer .el-button {
    width: 100px;
}
.search-style{
    margin-top: 10px;
}
.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 100px;
    height: 100px;
    line-height: 100px;
    text-align: center;
    border: 1px dotted #ccc;
  }
  .avatar {
    width: 120px;
    height: 120px;
    display: block;
  }
</style>
